function moveCircle(pm) {
	$('#circle').animate({
		left: 5 + $('#line').width() * (pm / 500)
	}, 1500)
}

function adapterTable(data) {
	for(var i = 0; i < data.length; i++) {
		$('#PmTable').append("<tr><td>" + (i + 1) + "</td><td>" + data[i].position_name + "</td><td>" + data[i].pm2_5 + "</td><td>" + data[i].quality + "</td></tr>")
	}
}

function getPMdata() {
	//	var args = new Object();
	//	args = GetUrlParms(); //获取参数数组
	//	//如果要查找参数key:
	//	if(args["city"] != undefined) {
	//		//如果要查找参数key:
	//		var city = args["city"];
	//		// encodeURI是什么？？？？？？？？？
	//		var urlAddress="http://www.pm25.in/api/querys/pm2_5.json?city=" + encodeURI(city) + "&token=5j1znBVAsnSf5xQyNQyq";
	//		$.ajax({
	//			url: urlAddress,
	//			dataType: 'jsonp',
	//			processData: false,
	//			type: 'get',
	//			success: function(data) {
	//				$('#address').text(data[0].area)
	//				$('#PmVaule').text(data[0].pm2_5)
	//				$('#PmDengji').text(data[0].quality)
	//				$('#Pmprimary').text(data[0].primary_pollutant)
	//				moveCircle($('#PmVaule').text())
	//				adapterTable(data)
	//			},
	//			error: function(XMLHttpRequest, textStatus, errorThrown) {}
	//		});

	var city = getUrlParam("city");
	var urlAddress = "http://www.pm25.in/api/querys/pm2_5.json?city=" + encodeURI(city) + "&token=5j1znBVAsnSf5xQyNQyq";
	$.ajax({
		url: urlAddress,
		dataType: 'jsonp',
		processData: false,
		type: 'get',
		success: function(data) {
			$('#address').text(data[0].area)
			$('#PmVaule').text(data[0].pm2_5)
			$('#PmDengji').text(data[0].quality)
			$('#Pmprimary').text(data[0].primary_pollutant)
			moveCircle($('#PmVaule').text())
			adapterTable(data)
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {}
	});
}

//获取URL所有参数
function GetUrlParms() {
	var args = new Object();
	var query = location.search.substring(1); //获取查询串   
	var pairs = query.split("&"); //在逗号处断开   
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('='); //查找name=value   
		if(pos == -1) continue; //如果没有找到就跳过   
		var argname = pairs[i].substring(0, pos); //提取name   
		var value = pairs[i].substring(pos + 1); //提取value   
		args[argname] = decodeURI(value); //存为属性   
	}
	return args;
}

//获取url中的参数
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg); //匹配目标参数
	if(r != null) return decodeURI(r[2]);
	return null; //返回参数值
}